package cn.tedu.management.building.controller;


import cn.tedu.management.building.pojo.dto.BuildingParam;
import cn.tedu.management.building.pojo.dto.BuildingQuery;
import cn.tedu.management.building.pojo.vo.BuildingVO;
import cn.tedu.management.building.service.BuildingService;
import cn.tedu.management.common.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "楼宇模块")
@RestController
@Slf4j
@RequestMapping("/v1/building/")
public class BuildingController {

    @Autowired
    private BuildingService buildingService;

    @ApiOperation("楼宇添加")
    @PostMapping("add")
    public JsonResult add(BuildingParam buildingParam){
        buildingService.addBuilding(buildingParam);
        return JsonResult.success();
    }

    @ApiOperation("楼宇删除")
    @PostMapping("delete")
    public JsonResult delete(Long id){
        buildingService.delete(id);
        return JsonResult.success();
    }

    @ApiOperation("楼宇编辑")
    @PostMapping("update")
    public JsonResult update(BuildingParam buildingParam){
        buildingService.update(buildingParam);
        return JsonResult.success();
    }

    @ApiOperation("楼宇查询")
    @PostMapping("select")
    public JsonResult select(BuildingQuery buildingQuery){
        List<BuildingVO> list = buildingService.select(buildingQuery);
        return JsonResult.success(list);
    }

    @ApiOperation("根据楼宇id查询楼宇信息")
    @PostMapping("selectById")
    public JsonResult selectById(Long id){
        BuildingVO buildingVO = buildingService.selectById(id);
        return JsonResult.success(buildingVO);
    }
}
